﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using XON.CapaNegocio;

namespace XON.XON_ASP
{
    public partial class Medicos_ABM : System.Web.UI.Page
    {
        ListaMedicos lm = new ListaMedicos();
        List<Medico> lmXape = null;
        int[] matriculas;
            
        protected void Page_Load(object sender, EventArgs e)
        {
             
        }

        protected void btnApeBusc_Click(object sender, EventArgs e)
        {
            int i = 0;
            Medico m1 = null;
            lmXape = lm.obtenerMedicos(txtApeBusc.Text);
            matriculas = new int[lmXape.Count];
            foreach (Medico m in lmXape)
            {
                if (m1 == null)
                {
                    m1 = m;
                    cargarInfo(m1);
                }
                matriculas[i] = m.getMatricula();
                lstMedicosBusc.Items.Add(m.getApellido() + ", " + m.getNombres());
                i++;
            }
        }

        protected void lstMedicosBusc_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (Medico m in lmXape)
            {
                if (m.getMatricula() == matriculas[lstMedicosBusc.SelectedIndex])
                    cargarInfo(m);
            }
        }

        protected void cargarInfo(Medico medico)
        {
            lblApellidoInfo.Text = medico.getApellido();
            lblNombresInfo.Text = medico.getNombres();
            lblMatriculaInfo.Text = medico.getMatricula().ToString();
            lblFchNacInfo.Text = medico.getFechaNacimiento().ToString();
        }
    }
}